<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="订单编号" width="95">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="商品名称">
        <template slot-scope="scope">
          {{ scope.row.goods_name }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="70">
        <template slot-scope="scope">
          <router-link :to="`/order/orderdetails/${scope.row.id}`">
            <el-button
              type="primary"
              class="el-icon-tickets"
              title="详细信息"
              size="mini"
              round
            ></el-button>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="发起者" width="80" align="center">
        <template slot-scope="scope">
          <span>发起者</span>
        </template>
      </el-table-column>
      <el-table-column label="接单者" width="80" align="center">
        <template slot-scope="scope">
          <span>接单者</span>
        </template>
      </el-table-column>
      <el-table-column
        class-name="status-col"
        label="订单状态"
        width="160"
        align="center"
      >
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{
            scope.row.status
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="created_at"
        label="最晚时间"
        width="180"
      >
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.create_at | showTime }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { parseTime } from "@/utils/index";
export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        "已下单，待付款": "info",
        "已付款，待审核": "danger",
        "已收货，待打钱": "danger",
        已完成: "success",
        "未付款，取消订单": "info",
        "已付款，取消订单": "danger",
        审核未通过: "info",
        "无人接单，取消订单": "danger",
        "未发货，取消接单": "danger"
      };
      return statusMap[status];
    },
    showTime(t) {
      return parseTime(new Date(t));
    }
  },
  data() {
    return {
      list: null,
      listLoading: true
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      this.listLoading = true;
      this.$http("getAllOrderList").then(res => {
        console.log(res.data.data);
        this.list = res.data.data;
        this.listLoading = false;
      });
    }
  },
  computed: {
    showTime(t) {
      return parseTime(t);
    }
  }
};
</script>
